home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / bin / kblueplugd < prev    next >
Text File  |  2008-10-09  |  2KB  |  60 lines

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. """
  4. Copyright (C) 2007 Achim Bohnet <allee@kubuntu.org>
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. """
  11.  
  12. import sys
  13. from   PyQt4 import QtCore, Qt
  14. import dbus
  15. import dbus.mainloop.qt
  16. import distutils.spawn
  17.  
  18. kbtcmd    = [ 'kbluetooth4' ]
  19. quitprogs = [ 'kbluetooth4' ]
  20.  
  21.  
  22. app = Qt.QCoreApplication(sys.argv)
  23.     
  24. dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
  25. bus = dbus.SystemBus()
  26.  
  27. try:
  28.         manager = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.bluez.Manager')
  29. except:
  30.         print "Unable to connect to bluez."
  31.         sys.exit(1)
  32.  
  33. if len(manager.ListAdapters()):
  34.         print "# of devices at startup:", len(manager.ListAdapters())
  35.         distutils.spawn.spawn(kbtcmd)
  36. else:
  37.         print "No BT device found"
  38.  
  39.  
  40. def slotAdapterAdded(device):
  41.         print "bt dev added:", device, "# of devices:", len(manager.ListAdapters())
  42.         distutils.spawn.spawn(kbtcmd)
  43.  
  44. def slotAdapterRemoved(device):
  45.         print "bt dev removed:", device, "# num of devices:", len(manager.ListAdapters())
  46.         if len(manager.ListAdapters()) == 0:
  47.                 for p in quitprogs:
  48.                         print "exiting:", p, " ..."
  49.                         try:
  50.                                 distutils.spawn.spawn(['dcop', p, 'MainApplication-Interface', 'quit'])
  51.                         except:
  52.                                 pass
  53.  
  54. manager.connect_to_signal("AdapterAdded", slotAdapterAdded)
  55. manager.connect_to_signal("AdapterRemoved", slotAdapterRemoved)
  56.  
  57. print "waiting for bt device (un)plug events ..."
  58.  
  59. app.exec_()
  60.